package com.zenithmind.library.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 预约状态枚举
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Getter
@AllArgsConstructor
public enum ReservationStatus {
    
    /**
     * 预约中
     */
    PENDING(0, "预约中"),
    
    /**
     * 可取书
     */
    AVAILABLE(1, "可取书"),
    
    /**
     * 已取书
     */
    FULFILLED(2, "已取书"),
    
    /**
     * 已取消
     */
    CANCELLED(3, "已取消"),
    
    /**
     * 已过期
     */
    EXPIRED(4, "已过期");
    
    private final Integer code;
    private final String description;
    
    /**
     * 根据代码获取枚举
     */
    public static ReservationStatus getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ReservationStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * 判断是否为活跃状态
     */
    public boolean isActive() {
        return this == PENDING || this == AVAILABLE;
    }
    
    /**
     * 判断是否已完成
     */
    public boolean isCompleted() {
        return this == FULFILLED || this == CANCELLED || this == EXPIRED;
    }
}
